<template>
  <div class="view-container">

    <table-search-view ref="orderView" :search-items="searchItems" :table-items="tableItems" :search-function="search">
      <template slot="insurance" slot-scope="scope">
        <span style="max-width: 100%;max-height: 5em;display: block;overflow: hidden;">{{getInsurance(scope.row.insurance)}}</span>
      </template>

      <template slot="action" slot-scope="scope">
        <action-logistics v-if="scope.row.process!=='intervened_not_repair'" :service="true" :scope="scope"></action-logistics>
        <action-repair-info :scope="scope" type="维修">维修详情</action-repair-info>
        <action-info :scope="scope"></action-info>
      </template>
    </table-search-view>

  </div>
</template>

<script>
  import TableSearchView from '@/components/TableSearchView';
  import actionOrderInfo from '../order/components/actionOrderInfo.vue';
  import actionRepairInfo from './components/actionServiceInfo.vue';
  import actionLogistics from '../order/components/actionLogistics.vue';

  import {getRepairList} from '@/api/afterService';

  export default {
    name: 'repairComplete', //维修完毕
    components: {
      'table-search-view':TableSearchView,
      'action-info':actionOrderInfo,
      'action-repair-info':actionRepairInfo,
      'action-logistics':actionLogistics,
    },
    data ()
    {
      return {
        searchItems: [
          {
            label: '商品名称',
            type: 'autocomplete',
            placeholder:'请输入商品名称',
            model:'goodsName',
          },
          {
            label: '申请维修时间',
            type: 'datetimerange',
            placeholder:'请选择申请维修时间',
            model:'timeRange',
          },
          {
            label: '订单编号',
            type: 'input',
            placeholder:'请输入订单编号',
            model:'orderNumber',
          },
          {
            label: '下单用户',
            type: 'input',
            placeholder:'请输入下单用户',
            model:'userName',
          }
        ],
        tableItems:[
          {
            label:'订单编号',
            prop:'orderNumber',
            width:'180px;',
          },
          {
            label:'商品名称',
            prop:'goodsName',
            width:'180px;',
            sortable:true,
          },
          {
            label:'下单用户',
            prop:'userName',
            width:'180px;',
            sortable:true,
          },
          {
            type:'scope',
            slot:'insurance',
            label:'保险',
            /*prop:'insurance',*/
            width:'180px;',
          },
          {
            label:'申请维修时间',
            prop:'createTime',
            width:'160px;',
            formatter:'parseTime',
          },
          {
            label:'维修进程',
            prop:'processStr',
            width:'160px;',
            sortable:true,
          },
          {
            type:'scope',
            label:'操作',
            slot:'action',
            width:'300px;',
          },
          {

          }
        ],
      }
    },
    methods: {
      search(data)
      {
        data.tab = 'repaired';
        return getRepairList(data);

        /*return new Promise(resolve => {
          let resp = {data:{total:10, list:[
            {
              "id": 85892,
              "goodsName": "oL5rUF4dk4",
              "userName": "L21NJQI3W3",
              "cost": 12396,
              "finishedTime": 123344455555,
              "state": "lease_finished",
              "stateStr": "租赁完成"
            },
            {
              "id": 85997,
              "goodsName": "0W7PoWYvp2",
              "userName": "yS56AKU8Ot",
              "cost": 77900,
              "finishedTime": 41442,
              "state": "lease_finished",
              "stateStr": "租赁完成"
            },
            {
              "id": 86256,
              "goodsName": "0vIUFI5xHn",
              "userName": "zYpYUMOJXr",
              "cost": 74056,
              "finishedTime": 123333244443,
              "state": "lease_finished",
              "stateStr": "租赁完成"
            }
          ]}};

          resolve(resp);
        });*/
      },
      getInsurance(insurance) //转换保险数组变成字符串
      {
        if(insurance && insurance.length)
        {
          let s = [];
          insurance.forEach(item=>{
            s.push(item.insuranceName || '');
          });

          return s.join(';');
        }
        return '';
      },
      actionSuccess() //操作成功,调用search方法
      {
        this.$refs['orderView'].search();
      },
    }
  }
</script>
